﻿using Microsoft.Extensions.Configuration;
using NSubstitute;

namespace Bigway.Common.Tests;

public static class Mocker
{
    public static IConfiguration CreateMockConfiguration(params KeyValuePair<string, string>[] extraKeyValues)
    {
        var mockConfig = Substitute.For<IConfiguration>();
        const string crmebConnectionString =
            "server=43.138.242.141;uid=java_mer_demo;pwd=DEmbc536BDPBFaYd;database=java_mer_demo";

        KeyValuePair<string, string>[] keyValues =
        [
            new("CrmebDbConnectionString", crmebConnectionString),
            new("ApiKey", "ed99f270-1cab-3ade-822b-81c08e30d57b"),
            new("CrmebFrontApiBaseUrl", "https://api.front.jingmeikeji.cc/api/front"),
            ..extraKeyValues
        ];

        foreach (var (key, value) in keyValues)
        {
            var mockConfigSection = Substitute.For<IConfigurationSection>();
            mockConfigSection.Value.Returns(value);
            mockConfig.GetSection(key)
                .Returns(mockConfigSection);
        }

        return mockConfig;
    }
}